package com.hmall.item.config;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/*********************************************************
 ** 将url请求参数中的时间字符串自动转换为LocalDateTime类型
 ** <br><br>
 ** @ClassName: LocalDateTimeConverter
 ** @author: yangfeng
 ** @date: 2024/12/16 14:39
 ** @version: 1.0.0
 *********************************************************/
@Configuration
public class LocalDateTimeConverter implements Converter<String, LocalDateTime> {

    @Override
    public LocalDateTime convert(String source) {
        if (StringUtils.isBlank(source)) {
            return null;
        }
        return LocalDateTime.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}


